package managent

import (
	"dub/app/web/managent/controller"
	"dub/app/web/managent/controller/agent"
	"dub/app/web/managent/controller/man"
	"dub/app/web/managent/mandefine"
	"dub/utils"
	"fmt"

	"github.com/astaxie/beego"
)

func RouteAdd() {

	//前台登录
	manController := &controller.AgentDefaultController{}
	beego.Router("/", manController, "get:Get")
	beego.Router("/", manController, "post:Post")

	//后台管理
	//代理
	managent := &man.AgentManController{}
	beego.Router("/man", managent, "*:Get")
	beego.Router("/man/findListAgent", managent, "*:FindListAgent")
	beego.Router("/man/toAddAgent", managent, "*:ToAddAgent")
	beego.Router("/man/addAgent", managent, "*:AddAgent")
	//后台管理基础功能
	baseFun := &man.AgentBaseFunController{}
	beego.Router("/basefun/findRegions", baseFun, "*:FindRegions")

	//会员管理
	mem := &agent.AgentMemController{}
	beego.Router("/agent/mem", mem, "*:Get")
	beego.Router("/agent/mem/toAdd", mem, "*:ToAdd")
	beego.Router("/agent/mem/addMem", mem, "*:AddMem")
	beego.Router("/agent/mem/uploadImg", mem, "*:UploadImg")
	beego.Router("/agent/mem/findMems", mem, "*:FindMems")
	beego.Router("/agent/mem/detailed", mem, "*:MemDetailed")
	//代理自己的功能
	ag := &agent.AgentController{}
	beego.Router("/agent/upPwd", ag, "*:UpPwd")
	//会员管理基础功能
	memBaseFun := &agent.AgentBaseFuncController{}
	beego.Router("/agent/basefun/findRegions", memBaseFun, "*:FindRegions")
	beego.Router("/agent/basefun/findMemLabels", memBaseFun, "*:FindMemLabels")
	//以下是测试路由
	beego.Router("/agent/basefun/toUploadImg", memBaseFun, "*:ToUploadImg")

}

func RegSessionGobStruct() {
	utils.RegSessionGobStruct()
}
func AddFunMap() {
	beego.AddFuncMap("c2int", utils.WebTemplateC2Int)
	beego.AddFuncMap("strhas", utils.WebTemplateStrHasArray)

	//页面调用时不用加被代理的url
	beego.AddFuncMap("authas", WebTemplateAuthHas)
}

func WebTemplateAuthHas(str string, strs []string) bool {
	return utils.WebTemplateStrHasArray(fmt.Sprintf("%s%s", mandefine.Proxy_Url, str), strs)
}
